package com.mojo.aspectbased;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 切面模块
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2021, 广州九尾信息科技有限公司
 * @date 2021/6/21 10:09
 */
//切面
@Aspect
@Component
public class AspectModule {
    //具体advice,前置增强
    @Before("selectAll()")
    public void beforeMethod() {
        System.out.println("before method execution...");
    }

    //切入点
    @Pointcut("execution(* com.mojo.aspectbased.LoginServiceImpl.*(..))")
    public void selectAll() {
    }

    //后置增强
    @After("selectAll()")
    public void afterMethod() {
        System.out.println("after method execution...");
    }

    //最终增强
    @AfterReturning("selectAll()")
    public void afterReturnMethod() {
        System.out.println("after returning method execution...");
    }

    //异常增强
    @AfterThrowing("selectAll()")
    public void afterThrowMethod() {
        System.out.println("throw exception method execution...");
    }

    //环绕增强
    @Around("selectAll()")
    public void aroundMethod(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("around method execution before...");
        proceedingJoinPoint.proceed();
        System.out.println("around method execution after...");
    }
}
